home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / SmallTalk / CObject.st < prev    next >
Text File  |  1995-08-25  |  8KB  |  512 lines

  1. "======================================================================
  2. |
  3. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  4. | Written by Steve Byrne.
  5. |
  6. | This file is part of GNU Smalltalk.
  7. |
  8. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  9. | under the terms of the GNU General Public License as published by the Free
  10. | Software Foundation; either version 1, or (at your option) any later version.
  11. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  12. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  14. | details.
  15. | You should have received a copy of the GNU General Public License along with
  16. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  17. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  18. |
  19.  ======================================================================"
  20.  
  21. "
  22. |     Change Log
  23. | ============================================================================
  24. | Author       Date       Change 
  25. | sbb         16 Feb 92      created summer 90.
  26. |
  27. "
  28.  
  29. !CObject methodsFor: 'inspection'!
  30.  
  31. inspect
  32.     ^self value printNl
  33. !!
  34.  
  35.  
  36. " ### Should keep scalar types from doing at: -- rehack to be basicAt:
  37.  and remove at: from class CScalar"
  38.  
  39. CObject variableWordSubclass: #CLong
  40.     instanceVariableNames: ''
  41.     classVariableNames: ''
  42.     poolDictionaries: ''
  43.     category: 'C variable access'!
  44.  
  45. !CLong class methodsFor: 'accessing'!
  46.  
  47. sizeof
  48.     ^4
  49. !
  50.  
  51. alignof
  52.     ^4
  53. !!
  54.     
  55. !CLong methodsFor: 'accessing'!
  56.  
  57. value
  58.     ^super at: 0 type: 4        "should be symbolic, but I want SPEED!"
  59. !
  60.  
  61. value: aValue
  62.     super at: 0 put: aValue type: 4
  63. !
  64.  
  65. sizeof
  66.     ^4
  67. !
  68.  
  69. alignof
  70.     ^4
  71. !!
  72.  
  73.  
  74. CObject variableWordSubclass: #CULong
  75.     instanceVariableNames: ''
  76.     classVariableNames: ''
  77.     poolDictionaries: ''
  78.     category: 'C variable access'!
  79.  
  80. !CULong class methodsFor: 'accessing'!
  81.  
  82. sizeof
  83.     ^4
  84. !
  85.  
  86. alignof
  87.     ^4
  88. !!
  89.     
  90.  
  91.  
  92. !CULong methodsFor: 'accessing'!
  93.  
  94. value
  95.     ^self at: 0 type: 5        "should be symbolic, but I want SPEED!"
  96. !
  97.  
  98. value: aValue
  99.     self at: 0 put: aValue type: 5
  100. !
  101.  
  102. sizeof
  103.     ^4
  104. !
  105.  
  106. alignof
  107.     ^4
  108. !!
  109.  
  110.  
  111. CObject variableWordSubclass: #CShort
  112.     instanceVariableNames: ''
  113.     classVariableNames: ''
  114.     poolDictionaries: ''
  115.     category: 'C variable access'!
  116.  
  117. !CShort class methodsFor: 'accessing'!
  118.  
  119. sizeof
  120.     ^2
  121. !
  122.  
  123. alignof
  124.     ^2
  125. !!
  126.     
  127.  
  128.  
  129. !CShort methodsFor: 'accessing'!
  130.  
  131. value
  132.     ^self at: 0 type: 2        "should be symbolic, but I want SPEED!"
  133. !
  134.  
  135. value: aValue
  136.     self at: 0 put: aValue type: 2
  137. !
  138.  
  139. sizeof
  140.     ^2
  141. !
  142.  
  143. alignof
  144.     ^2
  145. !!
  146.  
  147.  
  148. CObject variableWordSubclass: #CUShort
  149.     instanceVariableNames: ''
  150.     classVariableNames: ''
  151.     poolDictionaries: ''
  152.     category: 'C variable access'!
  153.  
  154. !CUShort class methodsFor: 'accessing'!
  155.  
  156. sizeof
  157.     ^2
  158. !
  159.  
  160. alignof
  161.     ^2
  162. !!
  163.     
  164. !CUShort methodsFor: 'accessing'!
  165.  
  166. value
  167.     ^self at: 0 type: 3        "should be symbolic, but I want SPEED!"
  168. !
  169.  
  170. value: aValue
  171.     self at: 0 put: aValue type: 3
  172. !
  173.  
  174. sizeof
  175.     ^2
  176. !
  177.  
  178. alignof
  179.     ^2
  180. !!
  181.  
  182.  
  183.  
  184. CObject variableWordSubclass: #CChar
  185.     instanceVariableNames: ''
  186.     classVariableNames: ''
  187.     poolDictionaries: ''
  188.     category: 'C variable access'!
  189.  
  190. !CChar class methodsFor: 'accessing'!
  191.  
  192. sizeof
  193.     ^1
  194. !
  195.  
  196. alignof
  197.     ^1
  198. !!
  199.     
  200. !CChar methodsFor: 'accessing'!
  201.  
  202. value
  203.     ^self at: 0 type: 0        "should be symbolic, but I want SPEED!"
  204. !
  205.  
  206. value: aValue
  207.     self at: 0 put: aValue type: 0
  208. !
  209.  
  210. sizeof
  211.     ^1
  212. !
  213.  
  214. alignof
  215.     ^1
  216. !!
  217.  
  218.  
  219.  
  220.  
  221. CObject variableWordSubclass: #CUChar
  222.     instanceVariableNames: ''
  223.     classVariableNames: ''
  224.     poolDictionaries: ''
  225.     category: 'C variable access'!
  226.  
  227. !CUChar class methodsFor: 'getting info'!
  228.  
  229. sizeof
  230.     ^1
  231. !
  232.  
  233. alignof
  234.     ^1
  235. !!
  236.  
  237. !CUChar methodsFor: 'accessing'!
  238.  
  239. value
  240.     ^self at: 0 type: 1        "should be symbolic, but I want SPEED!"
  241. !
  242.  
  243. value: aValue
  244.     self at: 0 put: aValue type: 1
  245. !
  246.  
  247. sizeof
  248.     ^1
  249. !
  250.  
  251. alignof
  252.     ^1
  253. !!
  254.  
  255.  
  256.  
  257. CObject variableWordSubclass: #CFloat
  258.     instanceVariableNames: ''
  259.     classVariableNames: ''
  260.     poolDictionaries: ''
  261.     category: 'C variable access'!
  262.  
  263. !CFloat class methodsFor: 'accessing'!
  264.  
  265. sizeof
  266.     ^4
  267. !
  268.  
  269. alignof
  270.     ^4
  271. !!
  272.     
  273. !CFloat methodsFor: 'accessing'!
  274.  
  275. value
  276.     ^self at: 0 type: 6        "should be symbolic, but I want SPEED!"
  277. !
  278.  
  279. value: aValue
  280.     self at: 0 put: aValue type: 6
  281. !
  282.  
  283. sizeof
  284.     ^4
  285. !
  286.  
  287. alignof
  288.     ^4
  289. !!
  290.  
  291.  
  292.  
  293. CObject variableWordSubclass: #CDouble
  294.     instanceVariableNames: ''
  295.     classVariableNames: ''
  296.     poolDictionaries: ''
  297.     category: 'C variable access'!
  298.  
  299. !CDouble class methodsFor: 'accessing'!
  300.  
  301. sizeof
  302.     ^8
  303. !
  304.  
  305. alignof
  306.     ^8                "### should ask system"
  307. !!
  308.     
  309. !CDouble methodsFor: 'accessing'!
  310.  
  311. value
  312.     ^self at: 0 type: 7        "should be symbolic, but I want SPEED!"
  313. !
  314.  
  315. value: aValue
  316.     self at: 0 put: aValue type: 7
  317. !
  318.  
  319. sizeof
  320.     ^8
  321. !
  322.  
  323. alignof
  324.     ^8
  325. !!
  326.  
  327.  
  328. CObject variableWordSubclass: #CString
  329.     instanceVariableNames: ''
  330.     classVariableNames: ''
  331.     poolDictionaries: ''
  332.     category: 'C variable access'!
  333.  
  334. !CString class methodsFor: 'getting info'!
  335.  
  336. sizeof
  337.     ^4
  338. !
  339.  
  340. alignof
  341.     ^4
  342. !!
  343.  
  344. !CString methodsFor: 'accessing'!
  345.  
  346. value
  347.     ^self at: 0 type: 8        "should be symbolic, but I want SPEED!"
  348. !
  349.  
  350. value: aValue
  351.     self at: 0 put: aValue type: 8
  352. !
  353.  
  354. sizeof
  355.     ^4
  356. !
  357.  
  358. alignof
  359.     ^4
  360. !!
  361.  
  362.  
  363.  
  364.  
  365. CObject variableWordSubclass: #CArray
  366.     instanceVariableNames: ''
  367.     classVariableNames: ''
  368.     poolDictionaries: ''
  369.     category: 'C variable access'!
  370.  
  371. !CArray methodsFor: 'accessing'!
  372.  
  373. at: anIndex
  374.     | type |
  375. "'in carray' printNl."
  376.     type _ self type.
  377. "'type is ' print. type inspect.
  378. 'index is ' print. anIndex printNl.
  379. 'subtype is ' print. type subType printNl.
  380. 'sizeof says ' print. type subType sizeof printNl."
  381.     ^self at: (anIndex * type subType sizeof) type: type subType
  382. "??? use baseType to hold component type info?"
  383. !
  384.  
  385. at: anIndex put: aValue
  386.     " ### Is this the right implementation?"
  387.     ^self at: 0 type: self type subType
  388. !
  389.  
  390. sizeof
  391.     | type |
  392.     type _ self type.
  393.     ^type numElements * type subType sizeof
  394. !
  395.  
  396. alignof
  397.     ^self type subType alignof
  398. !
  399.  
  400. inspect
  401.     | type |
  402.     type _ self type.
  403.     stdout nextPutAll: '['; nl.
  404.     1 to: type numElements do: 
  405.     [ :i | stdout nextPutAll: '    '.
  406.            self at: i inspect ].
  407.     stdout nextPutAll: ']'; nl
  408. !!
  409.  
  410. CObject variableWordSubclass: #CPtr
  411.     instanceVariableNames: ''
  412.     classVariableNames: ''
  413.     poolDictionaries: ''
  414.     category: 'C variable access'!
  415.  
  416.  
  417. !CPtr class methodsFor: 'accessing'!
  418.  
  419. sizeof
  420.     ^4
  421. !
  422.  
  423. alignof
  424.     ^4
  425. ! !
  426.  
  427.  
  428.  
  429. !CPtr methodsFor: 'accessing'!
  430.  
  431. deref
  432.     ^self value
  433. !
  434.  
  435. at: anIndex
  436.     | type |
  437.     type _ self type.
  438.     ^self at: (anIndex * type subType sizeof) type: 9
  439. !
  440.  
  441. value
  442.     ^self at: 0
  443. !
  444.  
  445. value: aValue
  446.     ^self at: 0 put: aValue type: nil
  447.     "Type doesn't matter"
  448. !
  449.  
  450. sizeof
  451.     ^4
  452. !
  453.  
  454. alignof
  455.     ^4
  456. !
  457.  
  458. inspect
  459.     stdout nextPutAll: '--> '.
  460.     self value inspect
  461. !!
  462.  
  463.  
  464.  
  465. CUChar variableWordSubclass: #CByte
  466.        instanceVariableNames: ''
  467.        classVariableNames: ''
  468.        poolDictionaries: ''
  469.        category: 'C variable access'
  470. !
  471.  
  472. CByte comment: 'You''re a marine.
  473. You adapt -- you improvise -- you overcome
  474.  
  475.                         - Gunnery Sgt. Thomas Highway
  476.                           Heartbreak Ridge'!
  477.  
  478. !CByte methodsFor: 'accessing'!
  479.  
  480. value
  481.     ^super value asciiValue
  482. !
  483.  
  484. value: anInteger
  485.     ^super value: (Character value: anInteger)
  486. !!
  487.  
  488. Smalltalk at: #CCharType
  489.       put: (CType baseType: CChar subType: CChar "0").
  490. Smalltalk at: #CUCharType
  491.       put: (CType baseType: CUChar subType: CUChar "1").
  492. Smalltalk at: #CShortType
  493.       put: (CType baseType: CShort subType: CShort "2").
  494. Smalltalk at: #CUShortType
  495.       put: (CType baseType: CUShort subType: CUShort "3").
  496. Smalltalk at: #CLongType
  497.       put: (CType baseType: CLong subType: CLong "4").
  498. Smalltalk at: #CULongType
  499.       put: (CType baseType: CULong subType: CULong "5").
  500. Smalltalk at: #CFloatType
  501.       put: (CType baseType: CFloat subType: CFloat "6").
  502. Smalltalk at: #CDoubleType
  503.       put: (CType baseType: CDouble subType: CDouble "7").
  504. Smalltalk at: #CStringType
  505.       put: (CType baseType: CString subType: CString).
  506. Smalltalk at: #CByteType
  507.       put: (CType baseType: CByte subType: CByte "0")
  508. !
  509.  
  510.